import Taro from "@tarojs/taro";
import * as TarojsComponents from "@tarojs/components";
import React from "react";
import ReactDOM from "react-dom";
import RequireJs from "./requirejs";

// const RequireJs = require("./requirejs").default;
const requirejs = new RequireJs();
const define = requirejs.define.bind(requirejs);

define("react", [], function () {
  return { ...React, default: React };
});
define("react-dom", [], function () {
  return { ...ReactDOM, default: ReactDOM };
});
define("@tarojs/taro", [], function () {
  return { ...Taro, default: Taro };
});
define("@tarojs/components", [], function () {
  return { ...TarojsComponents, default: TarojsComponents };
});
define("d8d-block", ["require", "exports"], function (require, exports) {
  "use strict";
  exports.__esModule = true;
  //   console.log("block", require, exports);
  return {
    useImport: function (moduleName) {
      if (moduleName.startsWith("d8d-")) {
        moduleName = moduleName.replace("d8d-", "");
      }
      //   return require(moduleName);
      //   return requirejs.requireModule(moduleName);
      const { has, requireModule } = requirejs;
      if (has(moduleName)) {
        const module = requireModule(moduleName);
        if (module?.default) return module.default;
        return module;
      }
    }
  };
});

// const appCode = require("./appCode");
// appCode?.run?.(define);
// const AppNodeId = appCode?.AppNodeId;

// const MainApp = requirejs.requireModule(AppNodeId);
// export default MainApp?.default;

export default requirejs